<?php

namespace app\store\model;
use app\common\model\UserRecordInfo as UserRecordInfoModel;
class UserRecordInfo extends UserRecordInfoModel
{
    /**
     * 获取文章列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList()
    {
        return $this->order(['create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);

    }
    /**
     * 新增记录
     * @param $data
     * @return false|int
     */
    public function add($data){
        return $this->save($data);
    }

    /**
     * 更新记录
     * @param $data
     * @param $id
     * @return false|int
     */
 /*   public function edit($data,$id){
        return $this->save($data,$id);
    }*/

    /**
     * 删除
     * @param $id
     * @return int
     */
    public static function del($id){
        return self::destroy($id);
    }

    public function detail($user_id){
        $data =  $this->where(['user_id'=>$user_id])->with(['userFamilyInfo','userJob'])->find();
        if(!empty($data['user_job'])){
            foreach ($data['user_job'] as $item){
                if(!empty($item->entry_time)){
                    $item->entry_time = date('Y-m-d',strtotime($item->entry_time));
                }
                if(!empty($item->leave_time)){
                    $item->leave_time = date('Y-m-d',strtotime($item->leave_time));
                }
            }
        }
        return $data;
    }
    public function details($id){
        $data =  $this->where(['id'=>$id])->find();
        return $data;
    }
    /**
     * 更新记录
     * @param $data
     * @return bool|int
     */
    public function edit($data,$id)
    {
        return $this->save($data,['id'=>$id]) !== false;
    }
}